


function getResults(data) {




}


function getSdata() {

  if(isLogin){

    if(localStorage.customerID){
      $.ajax({
          url: "https://www.sonystyle.com.cn/service/aicustomerservice/authentic/workClientAuthentic",
          type: "post",
          data: JSON.stringify({
            "type": "token",
            "content":localStorage.customerID,
             "key": 2
          }),
          contentType: "application/json",
          beforeSend: function (xhr) {
              xhr.setRequestHeader("Authorization", "Bearer " + localStorage.getItem("access_token"));
          },
          dataType: "json",
          cache: false,
          success: function (data) {
            if(data&&data.result){
              var returnData = data.returnData
              initUdesk(returnData)
            }
          },
          error: function () {}
      })
    }else{
      // $("#login").bPopup()
    }

  }



}




function gotoResult(channel) {

  var memberposturl = '/eSolverOmniChannel/account/getMemberInfo.do?channel=WEB';
  // memberposturl = 'https://walkman.sact-digital.cn/member.php?token='+localStorage.getItem('access_token');
  space.ajaxfunc2(memberposturl , localStorage.getItem('access_token'), "post", function (data) {
    var mes = data.resultMsg;
    if (mes[0].code == "00") {
      let res = data.resultData;
      let bpId = res.customerID;
      // localStorage.setItem("bpId", bpId);
      localStorage.setItem("customerID", bpId);
      localStorage.setItem("nickName", res.nickname);
      getSdata();
    } else {
      localStorage.removeItem("access_token");
      if(channel == "wechat"){
        getWopen();
      }else{
        toLogin();
      }
      
    }
  });
}

function getWopen() {
  if (localStorage.getItem('access_token') && localStorage.getItem('access_token') != "") {
    gotoResult("wechat");
  } else {
    const t = new JSCode('test', true)
    if (!t.code) {
      console.log('没有Code, 暂存状态，前往获取')
      t.fetch({ val: '暂存的字符串' })
    }
    t.ready(() => {
      Hybris.loginByCode(t.code).then((res) => {
        localStorage.setItem('access_token', res.data.resultData.access_token);
        gotoResult("wechat");
      }).catch((err) => {
        //getnoLogin("wechat");
        toLogin();

      })
    })

  }

}
function getAccess_tokens() {
  if (navigator.userAgent.match(/MicroMessenger/i)) {


    getWopen();



    /* wx.miniProgram.getEnv((res) => {
      if (!res.miniprogram) {
        getWopen()

      }else{
        if ($.getUrlParam('access_token') != null) {
          localStorage.setItem('access_token', $.getUrlParam('access_token'));
          
        }
        gotoResult("miniapp");
      }
    }) */
  } else {
    if (channel == "APP") {
      gotoResult("app");
    } else {
      gotoResult("wap");
    }

  }

}

if(getqs('access_token')!=''){
  localStorage.setItem('access_token',getqs('access_token'));
}


var checkReceiveAppInfo = function(){
  if(localStorage.getItem('reviceAppInfo')=='true'){
    setTimeout(()=>{
      localStorage.removeItem("reviceAppInfo");
      getAccess_tokens();
    },50)
  }else{
    setTimeout(()=>{
      checkReceiveAppInfo();
    },100)
  }
}





$(function () {
    

    // setTimeout(function () {


         if(isLogin){
           // if (localStorage.getItem("access_token") && localStorage.getItem("access_token") != "") {

           // }else{

              if (isSonyApp()) {
                checkReceiveAppInfo();
              }else{
                setTimeout(() => {

                  getAccess_tokens();
                
                }, 500)
                
              }

           // }
         }

        // var ua = window.navigator.userAgent.toLowerCase();
        // if (ua.match(/MicroMessenger/i) == 'micromessenger') {

        //     wx.miniProgram.getEnv((res) => {
        //         if (res.miniprogram) {
        //             if (getUrlParam('access_token') != null) {
        //                 localStorage.setItem('access_token', getUrlParam('access_token'));
        //                 getSdata();
        //             }else{

        //                 getSdata();

        //             }

        //         } else {
        //             autoLogin(function () {

        //                 getSdata();


        //             })


        //         }
        //     })
        // } else {
        //     autoLogin(function () {
        //         getSdata();

        //     })

        // }

    // }, 500)








})





function initUdesk(obj){
    // console.log(obj)
    var token = "" + (token = new Date()).getFullYear() + token.getMonth() + token.getDate() + Math.floor(Math.random(4)*10000);

    var scriptDom = document.createElement("script");
    scriptDom.src = "https://assets-cli.udesk.cn/ticket_sdk/ticket_sdk.js?t="+token;
    document.body.appendChild(scriptDom);

    var styleDom = document.createElement("link");
    styleDom.rel = "stylesheet";
    styleDom.href = "https://assets-cli.udesk.cn/ticket_sdk/ticket_sdk.css?t="+token;
    document.body.appendChild(styleDom);

    scriptDom.addEventListener('load', function() {
        var initobj = {
            // [Required] Must provide subdomain.
            subdomain:'sony.udesk.cn',
            // [Required] Must provide client appId.
            appid:'8917cb597c5ca8e4',
            // [Required] Must provide signature.
            signature: obj.signature,
            // [Required] Must provide type.
            type:'token',
            // [Required] Must provide content.
            content:obj.bpId,
             // container:'sdk'
            defaultUserData:{
               TextField_230821:  obj.aesBpId,
            },
        }

        console.log(initobj)
        window.udesk = UdeskSDK.ticketSDK.init(initobj);
        // Your code goes here...

          udesk.create({
            type: 'all', // new, detail, all
            mode: 'mobile',
            container: 'sdk-wrap',

          })


    }, false);
}





  $(function(){

    var submitname = 'shjd_mobile'

    $(document).on('click' ,'.baoming-btn',function(index){
      if(localStorage.access_token){
        // $('.sdk_box').show();
        // var s=s_gi(‘sonycnappdev2’);

        try{
          console.log(submitname='======try')
          var s=s_gi('sonycnappdev2');
          s.tl(this,'o',submitname)
          console.log(submitname+'====成功')
        }catch(e){}


        location.href = 'sdk.html'
        // location.href = 'http://127.0.0.1:8000/20230821/h5/sdk.html'

      }else{
        // $("#login").bPopup()
        toLogin();
      }

    })



    // $(document).on('click' ,'.sdk-wrap_box_master',function(index){
    //    $('.sdk_box').hide();

    // })


  })















